package com.igeek.oa.controller;

import com.igeek.oa.entity.Department;
import com.igeek.oa.result.Result;
import com.igeek.oa.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @User 訫
 * @Description TODO
 * @Date 2024/8/29 18:36
 */
@RestController
@RequestMapping("/dept")
@Api("部门表的控制层")
public class DepartmentController {
    @Autowired
    private IDepartmentService departmentService;

    @GetMapping("/getAllDepts")
    @ApiOperation("查询所有的部门信息")
    public Result getAllDepts() {
        try {
            List<Department> departments = departmentService.list();
            if(departments != null && !departments.isEmpty()){
                return new Result(true,"查询所有部门信息成功",departments);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return new Result(false,"查询所有部门信息失败");
    }
}
